import { createSlice } from "@reduxjs/toolkit";
import store from 'store2'
const adminSlice = createSlice({
    name: 'adminSlice',
    initialState: {
        loginState: store.get('users')?.loginState ?? false,
        adminUserInfo: {
            adminname: store.get('users')?.adminname ?? '',  // 管理员名字
            token: store.get('users')?.token ?? '',  // token令牌
            role: store.get('users')?.role ?? '',  // 管理员角色
            // TODO 注意这里的checkedKeys是需要传递的,而后端返回的是小写的checkedkeys
            checkedKeys: store.get('users')?.checkedKeys ?? [],  // 管理员权限数组 
        }
    },
    reducers: {
        setLoginState(state, action) {
            state.loginState = action.payload;
        },
        setAdminUserInfo(state, action) {
            state.adminUserInfo = action.payload;
        }
    }
})
export const { setLoginState, setAdminUserInfo } = adminSlice.actions;
export default adminSlice.reducer